package com.liy.cloud.auth.client.feign;

import com.liy.framework.common.extvo.ResultVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class AuthorizationFeignClientFallbackFactory implements FallbackFactory<AuthorizationFeignClient> {

    private static final Logger log = LoggerFactory.getLogger(AuthorizationFeignClientFallbackFactory.class);

    public AuthorizationFeignClient create(final Throwable e) {

        log.info("sys feign fallback; reason was: {}", e.getMessage());

        return new AuthorizationFeignClient() {
            public ResultVO authorization(String token) {
                return this.defaultResultVO();
            }

            public ResultVO hasPermission(String token, String code) {
                return this.defaultResultVO();
            }

            public ResultVO getUserPublicKey(String clientId, String secret) {
                return this.defaultResultVO();
            }

            public ResultVO permissionSync(Object obj) {
                return this.defaultResultVO();
            }

            private ResultVO defaultResultVO() {
                return new ResultVO(false, "认证服务异常: " + e.getMessage(), "500");
            }
        };
    }
}
